package conf2.ui;

import conf2.model.ESpecialCard;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.EnumMap;
import java.util.Map;
import javax.imageio.ImageIO;

public class Images {

    public enum Which {

        TABLE, APPICON, GREEN_TICK
    }
    private static Map<Which, BufferedImage> images = new EnumMap<Which, BufferedImage>(Which.class);
    private static Map<ESpecialCard, BufferedImage> specialCardImages =
            new EnumMap<ESpecialCard, BufferedImage>(ESpecialCard.class);
    private static Map<ESpecialCard, Image> smallSpecialCardImages =
            new EnumMap<ESpecialCard, Image>(ESpecialCard.class);


    public static void preload() {
        images.put(Which.TABLE, load("/conf2/images/table.jpg"));
        images.put(Which.APPICON, load("/conf2/images/appicon.png"));
        images.put(Which.GREEN_TICK, load("/conf2/images/green_tick.gif"));

        specialCardImages.put(ESpecialCard.A_KING_REVEALED, load("/conf2/images/a_king_revealed.png"));
        specialCardImages.put(ESpecialCard.CREBAIN_OF_DUNLAND, load("/conf2/images/crebain_of_dunland.png"));
        specialCardImages.put(ESpecialCard.GANDALF_THE_WHITE, load("/conf2/images/gandalf_white.jpg"));
        specialCardImages.put(ESpecialCard.GWAIHIR_THE_WINDLORD, load("/conf2/images/gwaihir_the_windlord.png"));
        specialCardImages.put(ESpecialCard.PALANTIR, load("/conf2/images/palantir.jpg"));
        specialCardImages.put(ESpecialCard.RECALL_TO_MORDOR, load("/conf2/images/mordor.jpg"));
        specialCardImages.put(ESpecialCard.SHADOWFAX, load("/conf2/images/shadowfax.jpg"));
        specialCardImages.put(ESpecialCard.THE_DARK_OF_MORDOR, load("/conf2/images/the_dark_of_mordor.png"));

        for (ESpecialCard c : specialCardImages.keySet()) {
            Image scaled = specialCardImages.get(c).getScaledInstance(45, 60, Image.SCALE_SMOOTH);
            smallSpecialCardImages.put(c, scaled);
        }
    }

    public static BufferedImage getSpecialCard(ESpecialCard c) {
        return specialCardImages.get(c);
    }

    public static Image getSmallSpecialCard(ESpecialCard c) {
        return smallSpecialCardImages.get(c);
    }

    public static BufferedImage get(Which image) {
        return images.get(image);
    }

    private static BufferedImage load(String path) {
        try {
            BufferedImage bi = ImageIO.read(Images.class.getResourceAsStream(path));
            return bi;
        } catch (IOException e) {
            return null;
        }
    }
}
